#include "agreemoney.h"
#include "ui_agreemoney.h"
#include "root.h"
#include <QMessageBox>
#include <QDebug>
#include "mainwindow.h"
#include <vector>
#include "bigsave.h"
#include "program.h"
extern vector <Program*> prdata;
int beg1=-1;
int en1=-1;
int now1=-1;
agreemoney::agreemoney(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::agreemoney)
{
    ui->setupUi(this);
    for(unsigned int i=0;i<prdata.size();i++)
    {
        if(prdata[i]->ifaskmoney()!=0)
         {   ui->lineEdit->setText(prdata[i]->showid());
            ui->lineEdit_2->setText(QString("%4").arg(prdata[i]->showvmoney()));
            beg1=i;
            now1=i;
        break;}
    }
    for(unsigned int i=prdata.size()-1;i>=0;i--){///寻找最后一个
        if(prdata[i]->ifaskmoney()!=0){
            en1 =i;
            break;}
    }
}

agreemoney::~agreemoney()
{
    delete ui;
}

void agreemoney::on_pushButton_2_clicked()
{
    this->close();
    root*p=new(root);
    p->show();
}

void agreemoney::on_pushButton_3_clicked()
{
    if(now1==beg1||now1==0){
        QMessageBox::information(this,"提示","这已经是第一个");
    }else{
    for(int i=now1-1;i>=beg1;i--){
        if(prdata[i]->ifaskmoney()!=0){
            now1=i;
        ui->lineEdit->setText(prdata[now1]->showid());
        ui->lineEdit_2->setText(QString("%4").arg(prdata[now1]->showvmoney()));
        break;
    }}}
}

void agreemoney::on_pushButton_4_clicked()
{
    if(now1==en1||now1==prdata.size()-1){
        QMessageBox::information(this,"提示","这已经是最后一个");
    }else {
        for(int i=now1+1;i<=en1;i++){
            if(prdata[i]->ifaskmoney()!=0){
                now1=i;
            ui->lineEdit->setText(prdata[now1]->showid());
            ui->lineEdit_2->setText(QString("%4").arg(prdata[now1]->showvmoney()));
            break;}
        }
    }
}

void agreemoney::on_pushButton_clicked()
{
    if(ui->radioButton->isChecked()==0&&ui->radioButton_2->isChecked()==0){
        QMessageBox::information(this,"提示","请选择同意或不同意按钮");}
        else if(ui->radioButton->isChecked()){ ///选中了同意
                prdata[now1]->givemoney();
                this->hide();
                bigsave();
                QMessageBox::information(this,"提示","同意申请资金成功");
                if(beg1==en1){
                root *p = new root;
                p->show();}
                else{
                    agreemoney *p = new agreemoney;
                    p->show();
                }
            }
        else {///选中的是不同意
                prdata[now1]->clearvirmoney();
                 this->hide();
                bigsave();
                QMessageBox::information(this,"提示","驳回申请资金成功");
                if(beg1==en1){
                root *p = new root;
                p->show();}
                else{
                    agreemoney *p = new agreemoney;
                    p->show();
                }
            }
}
